//////////////////////////////////////////////////////////////////////////////////
//
//	avamods admin
//		- Version 2.4
//		- 04.14.2008
//		- diamond-optic
//////////////////////////////////////////////////////////////////////////////////
//
// Credits:
//	- Zor, for AdminModX
//
// Information:
//
// - Extra admin commands used on the avamods server..
//
// - Put this plugin BEFORE adminchat.amxx (for gag purposes)
//
//////////////////////////////////////////////////////////////////////////////////
//
// Changelog:
//
// - 03.17.2006 Version 1.0
//	Initial Version
//	Took the cmds I use out of adminmodx and condensed them into this
//	Took some of the cmds from dod_cdrive (cdrive dod extras)
//
// - 03.26.2006 Version 1.1
//	Removed stuff and scaled down adminmodx (private version)
//
// - 03.26.2006 Version 1.2
//	Made stamina command a toggle
//
// - 03.31.2006 Version 1.3
//	Added setting variables to 0 on putinserver
//
// - 04.18.2006 Version 1.4
//	Fixed 'Normal Stamina' to match server custom plugin
//
// - 05.08.2006 Version 1.5
//	Commented out some of the client_print messages
//
// - 05.30.2006 Version 1.6
//	Added 'cdrive_health' to set your HP
//
// - 06.11.2006 Version 1.7
//	Added checks for is_user_connected
//	cdrive_health checks for a valid value (prevents suicide on invalid value)
//
// - 07.09.2006 Version 1.8
//	Replaced ENGINE with FAKEMETA
//
// - 09.01.2006 Version 1.9
//	Optimized & cleaned up code a bit
//	Changed zoom fov from 20 to 45
//	Added open/close cd drive
//
// - 11.19.2006 Version 2.0
//	Organized code a little bit (added some comments)
//	Added gag, shutup, and exec from 'AdminModX'
//
// - 01.28.2006 Version 2.1
//	Changed some returns
//	Added command to add kills to player's scores
//	Changed over from team cdrive to avamods
//
// - 05.28.2007 Version 2.2
//	Admins cant use commands against other admins (unless they have immunity flag)
//	Added command to set clip ammo (doesnt work for some guns, such as scoped fg42)
//	Got rid of the dumb way admin levels were handled
//
// - 07.19.2007 Version 2.3
//	Removed 'speak' precaches
//	Fixed bug in setting user kills
//	Added block for amx_chat on gagged users
//
// - 04.14.2008 Version 2.4
//	Various code optimizations
//	Changed default admin level for some commands
//	Added auto gag on reconnect attempt
//	Added screenshot command (moved to new plugin)
//	Added freeze command (moved to new plugin)
//	Moved cd open/close commands to a new plugin
//	Fixed some commands that had the wrong num of args
//	Added give scoped kar command (soon to be moved)
//	Renamed give garand command (soon to be moved)
//
//////////////////////////////////////////////////////////////////////////////////

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <fakemeta>
#include <engine>
#include <dodfun>
#include <dodx>


#define VERSION "2.4"
#define SVERSION "v2.4 - by diamond-optic (www.AvaMods.com)"

/////////////////////////////////////////////////
// Max steamids/gags to save
//
#define MAX_USERS 32

new dataSaved[MAX_USERS]
new dataAuth[MAX_USERS][32]
new dataPlace[33]
new dataLast

new invisible[33],stamina[33],zoom[33],gaged[33]
new gMsgSetFOV,gMsgFrags

public plugin_init()
{
	register_plugin("avamods admin",VERSION,"diamond-optic")
	register_cvar("avamods_admin_stats",SVERSION,FCVAR_SERVER|FCVAR_SPONLY)
	
	///////////////////////////////////////////////////////////
	// AVAMODS ADMIN COMMANDS - SECTION 1
	register_concmd("avamods_footsteps","admin_footsteps",ADMIN_LEVEL_H,"Turn on/off your footsteps")
	register_concmd("avamods_invis","admin_invis",ADMIN_LEVEL_H,"Toggle invisibility")
	register_concmd("avamods_stamina","admin_stamina",ADMIN_LEVEL_H,"Lock your stamina to 100")
	register_concmd("avamods_godmode","admin_godmode", ADMIN_LEVEL_H,"Toggle god mode")
	register_concmd("avamods_noclip","admin_noclip", ADMIN_LEVEL_H,"Toggle no-clip")
	register_concmd("avamods_health","admin_health", ADMIN_LEVEL_H,"admin_health <#> - Set your HP")
	register_concmd("avamods_zoom","admin_zoom",ADMIN_LEVEL_H,"zoom in/out")
	register_concmd("avamods_addkills","admin_addkills", ADMIN_LEVEL_H,"<nick/steam> <# of kills> - Adds kills to player's score")
	register_concmd("avamods_clipammo","admin_clipammo",ADMIN_LEVEL_H,"<ammo> - set your clip ammo")
	
	///////////////////////////////////////////////////////////
	// AVAMODS ADMIN COMMANDS - SECTION 2
	register_concmd("avamods_give_scopedkar","admin_scopedk98",ADMIN_LEVEL_H,"Give yourself a scoped kar")
	register_concmd("avamods_give_garand","admin_garand",ADMIN_BAN,"Give yourself a garand")
	register_concmd("avamods_colt","admin_colt",ADMIN_LEVEL_H,"Give yourself a colt 45")
	register_concmd("avamods_spade","admin_spade",ADMIN_LEVEL_H,"Give yourself a spade")
	register_concmd("avamods_grenade","admin_grenade",ADMIN_LEVEL_H,"Give yourself a grenade")
	register_concmd("avamods_ammo","admin_ammo",ADMIN_LEVEL_H,"Give yourself ammo")
	register_concmd("avamods_strip","admin_strip",ADMIN_LEVEL_H,"Strip your weapons")
	
	///////////////////////////////////////////////////////////
	// STANDARD ADMIN COMMANDS
	//
	//EXEC
	register_concmd("amx_exec","adminexec",ADMIN_LEVEL_G,"<nick/steam> <command> - This will execute a command on the clients machine")
	register_concmd("amx_execall","adminexec",ADMIN_LEVEL_G,"<command> - This will execute a command on all the clients machine")
	//SHUTUP
	register_concmd("amx_shutup","admin_shutup",ADMIN_KICK,"<nick/steam> - Stop ppl from using microphone")
	register_concmd("amx_unshutup","admin_shutup",ADMIN_KICK,"<nick/steam> - Allow ppl to use microphone again")
	//GAG
	register_concmd("amx_gag","admin_gag",ADMIN_KICK,"<nick/steam> - Gag a player - stops chat & microphone use")
	register_concmd("amx_ungag","admin_gag",ADMIN_KICK,"<nick/steam> - Un-Gag a player")
	//GAG BLOCKS
	register_clcmd("say","gag_block")
	register_clcmd("say_team","gag_block")
	register_concmd("amx_chat","gag_block",0,"<message> - sends message to admins")
	//
	///////////////////////////////////////////////////////////
	
	gMsgSetFOV = get_user_msgid("SetFOV")
	gMsgFrags = get_user_msgid("Frags")
}

public client_putinserver(id)
{
	if(is_user_connected(id) && !is_user_bot(id))
		{
		invisible[id] = 0
		stamina[id] = 0
		zoom[id] = 0
		gaged[id] = 0
		
		check_gagdata(id)
		}
}

public check_gagdata(id)
{	
	if(is_user_connected(id))
		{
		new authid[32]
		get_user_authid(id,authid,31)
		
		for(new i = 0; i < MAX_USERS; i++)
			{
			if(equali(dataAuth[i],authid) && dataSaved[i])
				{
				new nameAgainst[32],steamAgainst[32]
				get_user_name(id,nameAgainst, 31)
				get_user_authid(id,steamAgainst, 31)

				client_print(0,print_chat,"* AUTOGAG! %s reconnected while gagged...",nameAgainst)
				client_cmd(0,"spk scientist/c1a0_sci_stall")
				gaged[id] = 1
				set_speak(id,SPEAK_MUTED)
				
				dataPlace[id] = i
				
				log_amx("Reconnect Auto-Gag against %s<%s>",nameAgainst,steamAgainst)
				
				return PLUGIN_HANDLED
				}
			}
			
		dataPlace[id] = 0
		}
		
	return PLUGIN_HANDLED
}

public save_gagdata(id)
{
	new authid[32]
	get_user_authid(id,authid,31)
	
	if(dataPlace[id])
		{
		if(equali(dataAuth[dataPlace[id]],authid))
			{
			dataSaved[dataPlace[id]] = 1
			
			return PLUGIN_HANDLED
			}
		}
	else
		{			
		for(new i = 0; i < MAX_USERS; i++)
			{
			if(equali(dataAuth[i],authid))
				{
				dataSaved[i] = 1
				
				dataPlace[id] = i
				
				return PLUGIN_HANDLED
				}
			}
		
		dataAuth[dataLast] = authid
		dataSaved[dataLast] = 1
		
		if(dataLast >= MAX_USERS-1)
			dataLast = 0
		else
			dataLast++
		}
	
	return PLUGIN_CONTINUE
}

public remove_gagdata(id)
{
	new authid[32]
	get_user_authid(id,authid,31)
	
	if(dataPlace[id])
		{
		if(equali(dataAuth[dataPlace[id]],authid))
			{
			dataSaved[dataPlace[id]] = 0
			
			return PLUGIN_HANDLED
			}
		}
	else
		{			
		for(new i = 0; i < MAX_USERS; i++)
			{
			if(equali(dataAuth[i],authid))
				{
				dataSaved[i] = 0
				
				dataPlace[id] = i
				
				return PLUGIN_HANDLED
				}
			}
		
		dataAuth[dataLast] = authid
		dataSaved[dataLast] = 0
		
		if(dataLast >= MAX_USERS-1)
			dataLast = 0
		else
			dataLast++
		}
	
	return PLUGIN_CONTINUE
}

////////////////////////////////////////////////////////////////
//	clip ammo
//
public admin_clipammo(id,level,cid)
{
	if (!cmd_access(id,level,cid,2) || !is_user_connected(id) || !is_user_alive(id))
		return PLUGIN_HANDLED
	
	new arg[33],ClipAmmo
	read_argv(1,arg,32)
	ClipAmmo = str_to_num(arg)
		
	new ammo,clip,zGun = dod_get_user_weapon(id,clip,ammo)
	
	new WeaponName[32]
	get_dod_wpnname(zGun,WeaponName)
	
	set_clip(id,WeaponName,ClipAmmo)	
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	footsteps
//
public admin_footsteps(id,level,cid)
{
	if (!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(get_user_footsteps(id))
		{
		set_user_footsteps(id,0)
		client_print(id,print_chat,"Footsteps ON")
		}
	else
		{
		set_user_footsteps(id,1)
		client_print(id,print_chat,"Footsteps OFF")
		}
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	invisibility
//
public admin_invis(id,level,cid)
{
	if (!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(!invisible[id])	
		{
		invisible[id] = 1
		fm_set_entity_visibility(id,0)
		client_print(id,print_chat,"Invisiblilty ON")
		}
	else
		{
		invisible[id] = 0
		fm_set_entity_visibility(id,1)
		client_print(id,print_chat,"Invisibility OFF")
		}
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	stamina
//
public admin_stamina(id,level,cid)
{
	if (!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(!stamina[id])	
		{
		stamina[id] = 1
		dod_set_stamina(id,STAMINA_SET,100,100) 
		client_print(id,print_chat,"Stamina set to unlimited")
		}
	else
		{
		stamina[id] = 0
		dod_set_stamina(id,STAMINA_SET,15,100) 
		client_print(id,print_chat,"Stamina set to normal")
		}
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	godmode
//
public admin_godmode(id,level,cid)
{
	if(!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(!get_user_godmode(id))
		{
		set_user_godmode(id,1)
		client_print(id,print_chat,"Godmode ON")
		}
	else
		{
		set_user_godmode(id,0)
		client_print(id,print_chat,"Godmode OFF")
		}
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	noclip
//
public admin_noclip(id,level,cid)
{
	if (!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(!get_user_noclip(id))
		{
		set_user_noclip(id,1)
		client_print(id,print_chat,"No-Clip ON")
		}
	else
		{
		set_user_noclip(id,0)
		client_print(id,print_chat,"No-Clip OFF")
		}
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give scopedk98
//
 public admin_scopedk98(id,level,cid)
{
	if(cmd_access(id,level,cid,1) && is_user_connected(id))
		if(is_user_alive(id))
			give_item(id,"weapon_scopedkar")

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give garand
//
 public admin_garand(id,level,cid)
{
	if (!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id))
		{ 
		give_item(id,"weapon_garand")
		give_item(id,"ammo_garand")
		give_item(id,"ammo_garand")
		}

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give colt
//
public admin_colt(id,level,cid)
{
	if (!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id))
		{ 
		give_item(id,"weapon_colt")
		give_item(id,"ammo_colt")
		give_item(id,"ammo_colt")
		}

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give spade
//
public admin_spade(id,level,cid)
{
	if (!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id))
		give_item(id,"weapon_spade")

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give grenade
//
public admin_grenade(id,level,cid)
{
	if (!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id))
		{ 
		if(get_user_team(id) == 2)
			give_item(id,"weapon_stickgrenade")
		else
			give_item(id,"weapon_handgrenade")
		}

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give ammo
//
public admin_ammo(id,level,cid)
{
	if(!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id))
		{
		new ammo,clip,zGun = dod_get_user_weapon(id,clip,ammo)
		
		if(zGun==DODW_BAZOOKA || zGun==DODW_PANZERSCHRECK || zGun==DODW_PIAT)
			dod_set_user_ammo(id,zGun,10)
		else if(zGun==DODW_HANDGRENADE || zGun==DODW_STICKGRENADE || zGun==DODW_MILLS_BOMB)
			dod_set_user_ammo(id,zGun,3)
		else if(zGun == DODW_LUGER || zGun == DODW_COLT || zGun == DODW_WEBLEY)
			dod_set_user_ammo(id,zGun,200)
		else
			dod_set_user_ammo(id,zGun,300)
		}
		
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	strip weapons
//
public admin_strip(id,level,cid)
{
	if(!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id))
		strip_user_weapons(id)

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	health
//
public admin_health(id,level,cid)
{
	if(!cmd_access(id,level,cid,2) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id))
		{
		new arg[33],hp
		read_argv(1,arg,32)
		hp = str_to_num(arg)
		
		if(hp)
			{
			set_user_health(id,hp)
			client_print(id,print_chat,"Health set to: %d",hp)
			}
		else
			client_print(id,print_chat,"Invalid health value..")

		}

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	zoom
//
public admin_zoom(id,level,cid)
{
	if(!cmd_access(id,level,cid,1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		 
	if(!zoom[id])	
		{
		zoom[id] = 1
		
		message_begin(MSG_ONE_UNRELIABLE,gMsgSetFOV,{0,0,0},id)
		write_byte(45)
		message_end()
		
		client_print(id,print_chat,"* ZOOMED IN *")
		}
	else
		{
		zoom[id] = 0
		
		message_begin(MSG_ONE_UNRELIABLE,gMsgSetFOV,{0,0,0},id)
		write_byte(90)
		message_end()
		
		client_print(id,print_chat,"* ZOOMED OUT *")
		}

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	add kills
//
public admin_addkills(id,level,cid)
{
	if(!cmd_access(id,level,cid,2))
		return PLUGIN_HANDLED

	new playerName[32],argKills[4],numKills
	read_argv(1,playerName,31)
	read_argv(2,argKills,3)

	remove_quotes(playerName)
	numKills = str_to_num(argKills)
	
	// Search for the Player
	new player_id = get_player(playerName)

	if(player_id == -1)
		{
		if(id)
			client_print(id,print_console,"Client Not Found!!")

		return PLUGIN_HANDLED
		}

	new nameCalled[32],nameAgainst[32]
	new steamCalled[32],steamAgainst[32]
	get_user_name(id,nameCalled,31)
	get_user_authid(id,steamCalled,31)
	get_user_name(player_id,nameAgainst,31)
	get_user_authid(player_id,steamAgainst,31)

	//add the kills
	new kills = numKills + dod_get_user_kills(player_id)
	dod_set_user_kills(player_id,kills,0)
	
	message_begin(MSG_BROADCAST,gMsgFrags,{0,0,0},0)
	write_byte(player_id)
	write_short(kills)
	message_end()

	// Tell them it succeded
	if(id)
		client_print(id,print_console,"you have added %d kills to %s's score...",numKills,nameAgainst)

	// Now Log it
	log_amx("%s<%s> added %d kills to the score off %s<%s>",nameCalled,steamCalled,numKills,nameAgainst,steamAgainst)

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	Execute
//
public adminexec(id,level,cid)
{
	if(!cmd_access(id,level,cid,2))
		return PLUGIN_HANDLED

	new cmd[32],steam_nick_team[32],toexec[128]
	read_argv(0,cmd,32)
	read_args(toexec,128)

	replace(toexec,128,cmd,"")
	replace(cmd,32,"amx_exec","")

	// Get the info on the caller
	new nameCalled[32],steamCalled[32]
	get_user_name(id,nameCalled,31)
	get_user_authid(id,steamCalled,31)
	
	if(equal(cmd,"all"))
		{
		client_cmd(0,toexec)

		// Tell them it succeded
		if(id)
			client_print(id,print_console,"amx_execall <%s> succeeded on ALL",toexec)

		// Now Log it
		log_amx("%s<%s> Called amx_execall: %s against all",nameCalled,steamCalled,toexec)
		}

	else if(equal(cmd,""))
		{
		if(!cmd_access(id,level,cid,3))
			return PLUGIN_HANDLED

		read_argv(1,steam_nick_team,32)
		replace(toexec,128,steam_nick_team,"")

		// Search for the Player
		new player_id = get_player(steam_nick_team)

		if(player_id == -1)
			{
			// Give out error message
			if(id)
				client_print(id,print_console,"Client Not Found!!")

			return PLUGIN_HANDLED
			}

		client_cmd(player_id,toexec)

		// Get the info on the caller
		new nameAgainst[32],steamAgainst[32]
		get_user_name(player_id,nameAgainst,31)
		get_user_authid(player_id,steamAgainst,31)

		// Tell them it succeded
		if(id)
			client_print(id,print_console,"amx_exec <%s> succeeded on <%s>",toexec,nameAgainst)

		// Now Log it
		log_amx("%s<%s> Called amx_exec: %s against %s<%s>",nameCalled,steamCalled,toexec,nameAgainst,steamAgainst)
		}

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	Shuts up ppl
//
public admin_shutup(id,level,cid)
{
	if(!cmd_access(id,level,cid,2))
		return PLUGIN_HANDLED

	new cmd[32],playerName[32]
	read_argv(0,cmd,31)
	read_argv(1,playerName,31)

	remove_quotes(playerName)

	// Search for the Player
	new player_id = get_player(playerName)

	if(player_id == -1)
		{
		// Give out error message
		if(id)
			client_print(id, print_console,"Client Not Found!!")

		return PLUGIN_HANDLED
		}
		
	if(access(player_id,ADMIN_IMMUNITY))	//called AGAINST an admin with IMMUNITY
		{
		new callname[32],callsteam[32],againstname[32],againststeam[32]
		get_user_name(id,callname,31)
		get_user_authid(id,callsteam,31)
		get_user_name(player_id,againstname,31)
		get_user_authid(player_id,againststeam,31)
		
		client_print(player_id,print_chat,"* %s has attempted to %sshut you up *",callname,((equal(cmd,"amx_shutup")) ? "" : "un-"))
		
		log_amx("%s<%s> Attempted %sShutup against %s<%s>",callname,callsteam,((equal(cmd,"amx_shutup")) ? "" : "Un-"),againstname,againststeam)

		return PLUGIN_HANDLED
		}
	else if(access(player_id,ADMIN_KICK) && !access(id,ADMIN_IMMUNITY))	//called against an admin by another admin WITHOUT IMMUNITY
		{
		new callname[32],callsteam[32],againstname[32],againststeam[32]
		get_user_name(id,callname,31)
		get_user_authid(id,callsteam,31)
		get_user_name(player_id,againstname,31)
		get_user_authid(player_id,againststeam,31)
		
		//client_print(player_id, print_chat, "* %s has attempted to %sshut you up *",callname,((equal(cmd, "amx_shutup")) ? "" : "un-"))
		
		log_amx("%s<%s> Attempted %sShutup against %s<%s>",callname,callsteam,((equal(cmd, "amx_shutup")) ? "" : "Un-"),againstname,againststeam)

		return PLUGIN_HANDLED
		}
		
	new nameCalled[32],nameAgainst[32]
	new steamCalled[32],steamAgainst[32]
	get_user_name(id,nameCalled,31)
	get_user_authid(id,steamCalled,31)
	get_user_name(player_id,nameAgainst,31)
	get_user_authid(player_id,steamAgainst,31)

	if(equal(cmd,"amx_shutup"))
		{
		client_print(0,print_chat,"* Nobody wants to hear %s's microphone anymore...",nameAgainst)
		client_cmd(0,"spk scientist/shutup")
		set_speak(player_id,SPEAK_MUTED)
		
		save_gagdata(player_id)
		}
		
	else if(equal(cmd,"amx_unshutup"))
		{
		if(id == player_id)	
			{
			client_print(id,print_chat, "You are not allowed to unshutup yourself!")
	
			return PLUGIN_HANDLED
			}
		else
			{
			client_print(0,print_chat,"* %s is allowed to use their microphone again...",nameAgainst)
			set_speak(player_id,SPEAK_NORMAL)
			
			remove_gagdata(player_id)
			}
		}

	// Tell them it succeded
	if(id)
		client_print(id,print_console,"%s was successful",cmd)

	// Now Log it
	log_amx("%s<%s> Called %sShutup against %s<%s>",nameCalled,steamCalled,((equal(cmd,"amx_shutup")) ? "" : "Un-"),nameAgainst,steamAgainst)

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	Gags ppl
//
public admin_gag(id,level,cid)
{
	if(!cmd_access(id,level,cid,2))
		return PLUGIN_HANDLED

	new cmd[32],playerName[32]
	read_argv(0,cmd,31)
	read_argv(1,playerName,31)

	remove_quotes(playerName)

	// Search for the Player
	new player_id = get_player(playerName)

	if(player_id == -1)
		{
		// Give out error message
		if(id)
			client_print(id,print_console,"Client Not Found!!")

		return PLUGIN_HANDLED
		}

	if(access(player_id,ADMIN_IMMUNITY))	//called AGAINST an admin with IMMUNITY
		{
		new callname[32],callsteam[32],againstname[32],againststeam[32]
		get_user_name(id,callname,31)
		get_user_authid(id,callsteam,31)
		get_user_name(player_id,againstname,31)
		get_user_authid(player_id,againststeam,31)
		
		client_print(player_id, print_chat,"* %s has attempted to %sgag you *",callname,((equal(cmd,"amx_gag")) ? "" : "un-"))
		
		log_amx("%s<%s> Attempted %sGag against %s<%s>",callname,callsteam,((equal(cmd, "amx_gag")) ? "" : "Un-"),againstname,againststeam)

		return PLUGIN_HANDLED
		}
	else if(access(player_id,ADMIN_KICK) && !access(id,ADMIN_IMMUNITY))	//called against an admin by another admin WITHOUT IMMUNITY
		{
		new callname[32],callsteam[32],againstname[32],againststeam[32]
		get_user_name(id,callname,31)
		get_user_authid(id,callsteam,31)
		get_user_name(player_id,againstname,31)
		get_user_authid(player_id,againststeam,31)
		
		//client_print(player_id, print_chat, "* %s has attempted to %sgag you *",callname,((equal(cmd, "amx_gag")) ? "" : "un-"))
		
		log_amx("%s<%s> Attempted %sGag against %s<%s>",callname,callsteam,((equal(cmd,"amx_gag")) ? "" : "Un-"),againstname,againststeam)

		return PLUGIN_HANDLED
		}

	new nameCalled[32],nameAgainst[32]
	new steamCalled[32],steamAgainst[32]
	get_user_name(id,nameCalled,31)
	get_user_authid(id,steamCalled,31)
	get_user_name(player_id,nameAgainst,31)
	get_user_authid(player_id,steamAgainst,31)

	if(equal(cmd,"amx_gag"))
		{
		client_print(0,print_chat,"* %s is no longer allowed to use the chat or microphone...",nameAgainst)
		client_cmd(0,"spk scientist/shutup2")
		gaged[player_id] = 1
		set_speak(player_id,SPEAK_MUTED)
		
		save_gagdata(player_id)
		}

	else if(equal(cmd,"amx_ungag"))
		{
		if(id == player_id)	
			{
			client_print(id,print_chat,"You are not allowed to ungag yourself!")
	
			return PLUGIN_HANDLED
			}
		else
			{
			client_print(0, print_chat,"* %s is now allowed to use the chat & microphone again...",nameAgainst)
			gaged[player_id] = 0
			set_speak(player_id,SPEAK_NORMAL)
			
			remove_gagdata(player_id)
			}
		}

	// Tell them it succeded
	if(id)
		client_print(id,print_console,"%s was successful",cmd)

	// Now Log it
	log_amx("%s<%s> Called %sGag against %s<%s>",nameCalled,steamCalled,((equal(cmd,"amx_gag")) ? "" : "Un-"),nameAgainst,steamAgainst)

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	Checks to see if they are gaged
//
public gag_block(id)
{
	if(gaged[id])
		return PLUGIN_HANDLED

	return PLUGIN_CONTINUE
}

////////////////////////////////////////////////////////////////
// 	Searches for a player
//
get_player(search[])
{
	// See if they are there by exact nick
	new player_id = find_player("ahjl",search)

	// Try to find them by portion of nick
	if(!player_id)
		player_id = find_player("bhjl",search)

	// Try to find them by steam id
	else if(!player_id)
		player_id = find_player("chj",search)

	// Try to find them by ip
	else if(!player_id)
		player_id = find_player("dhj",search)

	// Try to find them by userid
	else if(!player_id)
		player_id = find_player("khj",search)

	if(!player_id)
		return -1

	return player_id
}

////////////////////////////////////////////////////////////////
//	invisibility stock  (fakemeta_util)
//
stock fm_set_entity_visibility(index,visible = 1)
{
	set_pev(index,pev_effects,visible == 1 ? pev(index,pev_effects) & ~EF_NODRAW : pev(index,pev_effects) | EF_NODRAW)

	return 1
}

////////////////////////////////////////////////////////////////
// get weapon name (stock by Wilson)
//
stock get_dod_wpnname( wpnID, szWpnName[32] )
{     
	xmod_get_wpnlogname(wpnID,szWpnName,31)
	format(szWpnName,31,"weapon_%s",szWpnName)
}

////////////////////////////////////////////////////////////////
// Set current clip (not backpack ammo) (stock by Wilson)
//
stock set_clip(id,const weapon[],clip)
{
	new currentent = -1, gunid = 0

	// get origin
	new Float:origin[3]
	pev(id,pev_origin,origin)
	//entity_get_vector(id,EV_VEC_origin,origin);
	
	while((currentent = find_ent_in_sphere(currentent,origin,Float:1.0)) != 0) {
		new classname[32]
		entity_get_string(currentent,EV_SZ_classname,classname,31)
	
		if(equal(classname,weapon))
			gunid = currentent
	
	}

	set_pdata_int(gunid,108,clip,4) // set their ammo  (115=scoped)
	
	return PLUGIN_CONTINUE
}
